From fd7e3020d2744cf1669a18b421e8c2daef45ab35 Mon Sep 17 00:00:00 2001 From: Ell Date: Sun, 10 Sep 2017 13:33:41 -0400 Subject: [PATCH] tools: add BablPolynomial test to trc-validator.c --- tools/trc-validator.c | 44 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/tools/trc-validator.c b/tools/trc-validator.c index c8663a9..fffbe94 100644 --- a/tools/trc-validator.c +++ b/tools/trc-validator.c @@ -1,13 +1,16 @@ -// utility program for validating lolremez approximation constants for TRCs +// utility program for validating lolremez approximation constants, and +// BablPolynomial based approximations, for TRCs // the currently used apprimxations for 1.8 and 2.2 gamma pow functions are // validated to be loss-less when coded for 8bit. +#include "config.h" #include #include #include #include +#include "babl-internal.h" -#if 1 +#if 0 #define GAMMA 2.2 @@ -130,6 +133,43 @@ static inline float to_linear (float x) } #endif +#if 1 + +#define GAMMA 2.2 +#define X0 ( 0.5f / 255.0f) +#define X1 (254.5f / 255.0f) +#define DEGREE 6 +#define SCALE 2 + +static inline float from_linear (float x) +{ + if (x >= X0 && x <= X1) + { + BablPolynomial poly; + + babl_polynomial_approximate_gamma (&poly, + 1.0 / GAMMA, X0, X1, DEGREE, SCALE); + + return babl_polynomial_eval (&poly, x); + } + return powf (x, 1.0f/GAMMA); +} + +static inline float to_linear (float x) +{ + if (x >= X0 && x <= X1) + { + BablPolynomial poly; + + babl_polynomial_approximate_gamma (&poly, + GAMMA, X0, X1, DEGREE, SCALE); + + return babl_polynomial_eval (&poly, x); + } + return powf (x, GAMMA); +} +#endif + static inline float from_linear_ref (float x) { return powf (x, 1.0/GAMMA); -- 2.30.2